{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "768691e2",
   "metadata": {},
   "source": [
    "## 1. 冒泡排序法\n",
    "\n",
    "可视化动态展示排序过程: \n",
    "导入 matplotlib.pyplot, 实现每一轮排序后元素相对位置显示的更新\n",
    "\n",
    "数据初始化： 生成一个连续的数据列表，并将其随机排列 -> from random import shuffle\n",
    "\n",
    "通过定义一个变量： swapped 用来标记排序过程是否结束\n",
    "具体逻辑在于：在排序逻辑前将swapped置为False, 排序完成后将其置为True\n",
    "\n",
    "声明一个函数：bubblesort_anim"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1688732f",
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "from random import shuffle\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "def bubblesort_anim(numList: List) -> None:\n",
    "    x = len(numList)\n",
    "    swapped = True\n",
    "    while(swapped):\n",
    "        plt.figure(1)\n",
    "        swapped = False\n",
    "        for i in range(x -1):\n",
    "            if numList[i] > numList[i+1]:\n",
    "                numList[i], numList[i+1] = numList[i+1], numList[i]\n",
    "                swapped = True\n",
    "        plt.plot(list(range(x)), numList, \"k.\", markersize=6)\n",
    "        plt.pause(0.01)\n",
    "        plt.clf() # 这个清除绘图窗口的命令在jupter中似乎不起作用\n",
    "\n",
    "def main():\n",
    "    numList = list(range(300))\n",
    "    shuffle(numList)\n",
    "    bubblesort_anim(numList)\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    main()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "26f6f5f1",
   "metadata": {},
   "source": [
    "## 2. gitingest：临时目录下的文件处理\n",
    "\n",
    "结合项目的业务背景，有一些附加条件限制：\n",
    "遍历特定临时目录下的文件夹（已经确定该目录下是具有相同格式的文件目录）：TEMP_BASE_PATH\n",
    "    比较文件夹的存在时间 -> current_live_time 与规定存在的时间限制，若超出规定的“生存时间” -> TEMP_LIVE_TIME\n",
    "        则按照一定的规则处理对应的文件夹：\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4dd8521c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time\n",
    "import tempfile\n",
    "from pathlib import Path\n",
    "from typing import List\n",
    "\n",
    "TMP_BASE_PATH = Path(tempfile.gettempdir()) / \"gitingest_test_for_study\"\n",
    "\n",
    "def _remove_old_repositories():\n",
    "    try:\n",
    "        if not TMP_BASE_PATH:\n",
    "            print(f\"{TMP_BASE_PATH} doesn't exist...\")\n",
    "            return False\n",
    "        \n",
    "        current_time = time.time()\n",
    "        for folder in TMP_BASE_PATH.iterdir():\n",
    "            if current_time - folder.stat().st_mtime < 60 :\n",
    "                continue  # Skip if the folder was modified in the last 60 seconds\n",
    "            if folder.is_dir():\n",
    "                print(f\"removing old repository: {folder}\")\n",
    "        return True\n",
    "\n",
    "    except Exception as exc:\n",
    "        print(f\"something error happend in function '_remove_old_repositories'. {exc}\")\n",
    "\n",
    "        "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "env_py38",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.18"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
